<template>
    <view class="ee4" style="height: 100%;">
		<web-view :src="srcurl"></web-view>
    </view>
</template>
<script>
	import {
	    KmsScourseStudying
	} from '@/api/kms/course.js';
	export default {
	    data() {
	        return {
				ops: {
				// 	"_watermark": "语祯物联",
				　　"_saveable": false, //是否允许保存PDF，默认true
				　　"_printable": false, //是否允许打印PDF，默认true
				　　"_copyable": false, //是否允许选择复制内容，默认true
				　　"_title": "文档预览", //自定义标题
				},
				webviewStyles: {
					progress: {
						color: '#FF3333',
					}
				},
	            srcurl : "", // 下载文件的网络地址
				inTime: new Date(),
				courseId: '',
				fileId:'',
				// 计时器
				timer: '',
				//更新文件的阅读时间
				nowTime: ''
	        };
	    },
		
		computed:{
		},
		onReady(res) {
			// this.srcUrl = "https://yuzhen-moses.oss-cn-shanghai.aliyuncs.com/SAAS-CRM/54e2a7ee56164b388ce9f5350caf3c8cpreview.docx"
			// for (var a in this.ops) {
			// 　　this.srcUrl += "&" + encodeURIComponent(a) + "=" + encodeURIComponent(this.ops[a]);
			// }
			
		},
		onLoad(option) {
			this.courseId = option.courseId
			this.fileId = option.fileId
			// this.timer = setInterval(this.getScourseStudying, 3000);
			this.nowTime = new Date().getTime()/1000
			this.srcurl = `/hybrid/html/web/viewer.html?file=`+encodeURIComponent(option.path)
		},
		onShow() {
			
		},
		watch:{},
	    methods: {
			getScourseStudying(time) {
			    let self = this;
			    let params = {
			        courseId: this.courseId,
					fileId: this.fileId,
					studiedSeconds:  parseInt(Math.round(time)),
					studiedToSeconds: ''
			    }
			    KmsScourseStudying(params).then(res => {
					this.nowTime = ''
			    })
			}
	    },
		destroyed() {
			var endTime = new Date().getTime()/1000
			var secondTime = endTime-this.nowTime
			this.getScourseStudying(secondTime)
			// var time = (leaveTime.getTime() - this.inTime.getTime())/1000
			// clearInterval(this.timer)
			// this.getScourseStudying(time)
		}
	};
</script>

<style>
</style>
